<?php
	echo $this->Html->css('/lil_media/css/lil_media');
?>
<h1><?php __('Media Index'); ?></h1>
<div class="index" id="MediaIndex">
<?php
	foreach ($data as $item) {
		$path_parts = pathinfo($base_path . DS . $item['filename']);
		
		echo '<div class="media_item">';
		
		$icon = '';
		if (in_array(strtolower($path_parts['extension']), array('gif', 'png', 'jpg'))) {
			$icon = $this->Html->image($www_dir . $path_parts['basename']);
		} else if (in_array(strtolower($path_parts['extension']), array('doc', 'docx'))) {
			$icon = $this->Html->image('doc.gif');
		} else if (in_array(strtolower($path_parts['extension']), array('xls', 'xlsx'))) {
			$icon = $this->Html->image('xls.gif');
		} else if (strtolower($path_parts['extension']) == 'pdf') {
			$icon = $this->Html->image('pdf.gif');
		} else {
			$icon = $this->Html->image('x.gif');
		}
		
		echo $this->Html->link(
			$icon,
			array(
				'action'   => 'view',
				'path'     => (!empty($this->params['named']['path'])) ?
					$this->params['named']['path'] : null,
				'filename' => $path_parts['basename']
			),
			array('escape' => false)
		);
		
		echo '<div class="media_name">';
		echo $this->Html->link(
			$path_parts['basename'],
			array(
				'action' => 'view',
				'path'   => (!empty($this->params['named']['path'])) ?
					$this->params['named']['path'] : null,
				'filename'   => $path_parts['basename']
			)
		);
		echo '</div>';
		echo '</div>';
	}
?>
</div>